#include <iostream>
#include "Car.h"
#include "student.h"
#include "allocation.h"
#include "radar.h"
#include "chassis.h"
using namespace std;



int main()
{
	
	auto radar = std::make_shared<Radar>();//实例化雷达
    auto chassis = std::make_shared<Chassis>();//实例化底盘
    radar->registerObserver(chassis.get());//\/注册雷达观察者1
	// 智能车编号
	string carIDs[10] = {
        "cqusn1A2B3C4D",
        "cqusn5E6F7G8H",
        "cqusn9I0J1K2L",
        "cqusn3M4N5O6P",
        "cqusn7Q8R9S0T",
        "cqusn1U2V3W4X",
        "cqusn5Y6Z7A8B",
        "cqusn9C0D1E2F",
        "cqusn3G4H5I6J",
        "cqusn7K8L9M0N"
    };
	// 学生信息
	string students_ID[10][2] = {  
        {"S001", "张三"},
        {"S002", "李四"},
        {"S003", "王五"},
        {"S004", "赵六"},
        {"S005", "孙七"},
        {"S006", "周八"},
        {"S007", "吴九"},
        {"S008", "郑十"},
        {"S009", "王十一"},
        {"S010", "冯十二"}
    };
	SmartCar CAR[10];  //实例化智能车类
	Student students[10];  //实例化学生类
	int num = 10;
	for(int i=0;i<num;i++)
	{
		CAR[i].set_CAR_ID(carIDs[i]);//设置车编号
		CAR[i].SET_Chassis(); //设置底盘信息为默认值
		CAR[i]. SET_AGXKit(); //设置AGX套件信息为默认值
		CAR[i]. SET_StereoCamera(); //设置双目摄像头信息为默认值
		CAR[i].SET_LiDAR(); //设置多线激光雷达信息为默认值
		CAR[i]. SET_Battery(); //设置电池模块信息为默认值
		CAR[i].SET_Display(); //设置液晶显示屏信息为默认值
		CAR[i]. SET_Gyroscope();  //设置9轴陀螺仪信息为默认值
	}
	for(int i=0;i<num;i++)
	{
	 students[i].set_Student(students_ID[i][0],students_ID[i][1]); //设置学生信息
	}
	cout << "分配并写入文件中。。。" << endl;
	for(int i=0;i<num;i++)
	{
	 students[i].saveToFile("car.txt",i);  //写入文件
	 CAR[i].saveToFile("car.txt",i);  //写入文件
	}
	cout << "！！写入完成！！" << endl;
    

	
	int X = 1; // 初始化变量 X  
    char input;  
	printCarFromFile("car.txt",0);
    cout << "按n键显示下一辆小车信息,按p显示上一辆小车信息 " << endl;  
    while (true) {  
        cin >> input; // 读取一个字符 
		// 模拟从命令行获取障碍物状态
        radar->setObstacleStatus(((int)input-48)); 
        // 将输入转换为小写，以便不区分大小写  
        input = tolower(input);  
        switch (input) {  
            case 'n':  
			    if(X==num)
				{
					cout << " 已经是最后一辆 " << endl;
					break; 
				}
                X++;  
                printCarFromFile("car.txt",(X-1)); 
                break;  
            case 'p':  
			    if(X==1)
				{
					cout << " 已经是第一辆 " << endl;
					break; 
				}
                X--;  
                printCarFromFile("car.txt",(X-1)); 
                break;  
        } 
	
	
    }  

}